package Week6.J0522;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class 包含不超过两种字符的最长字串_xv {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        char[] arr = scanner.next().toCharArray();
        Map<Character, Integer> map = new HashMap<>();
        int left = 0, right = 0, ret = 0;
        while (right < arr.length) {
            map.put(arr[right], map.getOrDefault(arr[right], 0) + 1);
            right++;

            while (map.size() > 2) {
                int leftChar = map.get(arr[left]);
                leftChar--;
                map.put(arr[left], leftChar);
                if (leftChar == 0) {
                    map.remove(arr[left]);
                }
                left++;
            }

            ret = Math.max(ret, right - left);
        }
        System.out.println(ret);
    }
}
